import java.util.Scanner;
//9.11
// 非公共类：放在公共类之前或之后均可
class LinearEquation {
    // 私有数据字段：存储方程组系数
    private double a;
    private double b;
    private double c;
    private double d;
    private double e;
    private double f;

    // 构造函数：初始化所有系数
    public LinearEquation(double a, double b, double c, double d, double e, double f) {
        this.a = a;
        this.b = b;
        this.c = c;
        this.d = d;
        this.e = e;
        this.f = f;
    }

    // 访问器方法（getter）
    public double getA() {
        return a;
    }

    public double getB() {
        return b;
    }

    public double getC() {
        return c;
    }

    public double getD() {
        return d;
    }

    public double getE() {
        return e;
    }

    public double getF() {
        return f;
    }

    // 判断方程组是否有解（ad - bc ≠ 0）
    public boolean isSolvable() {
        return (a * d - b * c) != 0;
    }

    // 计算 x 的解：x = (ed - bf) / (ad - bc)
    public double getX() {
        if (!isSolvable()) {
            throw new IllegalStateException("方程组无解，无法计算 x");
        }
        return (e * d - b * f) / (a * d - b * c);
    }

    // 计算 y 的解：y = (af - ec) / (ad - bc)
    public double getY() {
        if (!isSolvable()) {
            throw new IllegalStateException("方程组无解，无法计算 y");
        }
        return (a * f - e * c) / (a * d - b * c);
    }
}

// 公共类：类名必须与文件名（TestLinearEquation.java）一致
public class TestLinearEquation {
    public static void main(String[] args) {
        // 创建 Scanner 对象接收用户输入
        Scanner scanner = new Scanner(System.in);

        // 提示用户输入 6 个系数
        System.out.println("请输入线性方程组的系数 a, b, c, d, e, f（以空格分隔）：");
        double a = scanner.nextDouble();
        double b = scanner.nextDouble();
        double c = scanner.nextDouble();
        double d = scanner.nextDouble();
        double e = scanner.nextDouble();
        double f = scanner.nextDouble();

        // 创建 LinearEquation 对象
        LinearEquation equation = new LinearEquation(a, b, c, d, e, f);

        // 判断是否有解并输出结果
        if (equation.isSolvable()) {
            // 有解：输出 x 和 y（保留 4 位小数，提高可读性）
            System.out.printf("方程组的解为：\n");
            System.out.printf("x = %.4f\n", equation.getX());
            System.out.printf("y = %.4f\n", equation.getY());
        } else {
            // 无解：提示信息
            System.out.println("The equation has no solution.");
        }

        scanner.close(); // 关闭 Scanner
    }
}
